<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/view/include/css-include.jsp"%>
<%@ include file="/view/include/jsp-include.jsp"%>
<%@ include file="/view/include/jquery-include.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Authority Manage</title>

<script type="text/javascript">
	$().ready(function() { 
		view(1);  
		$("#onWrite").bind("click",function(){
            location="/authorityWrite.html";            
        });
	    /* 조회버튼 */
	    $("#btnSearch").bind("click",function(){      
	    	view(1);
	    });
	    
	});

	function view(page){
		$.post(
                '/getAuthorityView.json', {                      
                paging : page,
                listScale : "15",
                userId : $("#userId").val(),
                userName : $("#userName").val()
               },
            function(data) {
                //$("#authorityDetail").remove();
                //reSetValidete(); //벨류데이션 초기화
                searchDataMaping(data);    //DATA맵핑 
            });
	}

	/* searchData 맵핑 */
    function searchDataMaping(data){
    	   
    	var contents = "";
    	var cHeader = "<tr>"
    		+"<th width='120px'>User Id</th>"
    		+"<th width='*'>User Name</th>"
    		+"<th width='150px'>Role Name</th> "                       
    		+"<th width='70px'>U</th>"
    		+"</tr>";
        if(data.resultList.length == 0){
            contents = "<tr><td colspan='4' height='50' bgcolor='#FFFFFF' align='center'><B>No Data</B></td></tr>";
            $("#authorityDetail").html(cHeader+contents);
                
        }else{  
	        $.each(data.resultList, function(index){  // List로 받아온값 (여러건)  
	           contents += "<tr style='cursor:pointer' onclick='rowSelect(this, \""+this.userId+"\")'><td align='center'>"+this.userId+"</td>"
	               +"<td align='left' class='boSub'>"+this.userName+"</td>"           
	        	   +"<td align='center'>"+this.roleName+"</td>"
	        	   +"<td align='center'><a href='javascript:onUpdate(\""+this.userId+"\");'><img src='images/web/ic_up.gif' alt='Update' id='onUpdate'/></a></td>"
	               +"</tr>";
	        });
        }
        
        var totalPage = Math.ceil(parseInt(data.customeCount)/parseInt(15));        
        $("#spanCount").empty().html("Total : "+data.customeCount);
        $("#pageCount").empty().html("Page : "+$("#pageNum").val()+" / "+totalPage);                    
        $("#page").empty().html(data.pageSplit);
        
        $("#authorityDetail").html(cHeader+contents); // 조회 값 뿌리기
        $("#authorityDetail tr:eq(1)").click(); 
        
    }
    
    function onUpdate(arg){
    	location="/authorityUpdate.html?userId="+arg;
    }

    function onDel(arg){
    	$.post(
                '/delAuthority.json', {  
                custCode : arg
               },
            function(data) {
           	   if(data.result == true){
                   alert("Deleted.....!");
                   view($("#pageNum").val());    
           	   }else{
           		   alert("ERROR!");
           	   }  
            });
    }

    function ajaxPageSplit(num) {
    	$("#pageNum").val(num);
        view(num);
    }
    
    var userIdTmp = "";
    function rowSelect(obj, userId){
    	userIdTmp = userId;
        $("#authorityDetail tr").css("backgroundColor","#FFFFFF");
        obj.style.backgroundColor="#e0eeee";  
        document.ondblclick=dblclick;
    }

    function dblclick(){
        onUpdate(userIdTmp);
    }
</script>
</head>
<body>
<div class="wrap">
	<div class="pagetitle">
    	<h1>AUTH LIST</h1>
	</div>
    <div>
    	<table class="TableST">
            <tr>
            	<th>User Id</th>
                <td>
                	<input type="text" class="inST" name="userId" id="userId"/>
                </td>
                <th>User Name</th>
                <td>
                	<input type="text" class="inST" name="userName" id="userName"/>
                </td>
            </tr>
        </table>
        <div class="bo_btnS">
            <ul class="btnst"><li class="a"><a href="#" id="btnSearch" >SEARCH</a></li></ul>
        </div>
        <br/><br/><br/><br/>
        <ul>
        	<li class="totaltext"><span id="spanCount">Total : 0</span></li>
            <li class="pagetext"><span id="pageCount">Page : 1&frasl;1</span></li>
            <li class="bolistW">
            	<table class="TableST4" id="authorityDetail">
                	<!-- tr>
                    	<th width="65px">User Id</th>
                        <th width="65px">User Name</th>
                        <th width="65px">Role Name</th>                        
                        <th width="20px">U</th>
                    </tr>
                    <span id="authorityDetail">
	                    <tr>
	                       <td colspan="4"></td>	
	                    </tr>
                    </span-->                    
                </table>
            </li>
        </ul>
    </div>
    <div class="page_wrap">
        <div class="page" id="page" >
        </div>
    </div>
    <input type="hidden" name="pageNum" id="pageNum" value="1">
</div>
</body>
</html>